<?php
namespace App\Exports;

use App\Http\Services\CommonManager;
use App\Merchant;
use App\OrderAddress;
use App\Orders;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithMapping;

class MoneyExport implements FromArray
{
    protected $orderId = [];

    public function __construct($orderId)
    {
        $this->orderId = $orderId;
    }

    public function array(): array
    {
        $data = [];
        $temp=[
            '订单号','门店','原价','优惠金额','折扣价格','类型','付款金额','支付方式','备注','交易时间'
        ];

        array_push($data,$temp);

        $orderList = Orders::whereIn('id',$this->orderId)->get();
        if(count($orderList) > 0){
            foreach ($orderList as $order) {
                $merchantName = Merchant::getMerchantName($order->merchant_id);
                $moneyType   =$order->status == 6 ? '订单退款' : '订单收入';

                $value = [
                    $order->order_num,$merchantName,
                    $order->original_price,$order->coupon_reduce_price,
                    round($order->original_price - $order->discount_price,2),$moneyType,
                    $order->pay_amount,$order->pay_way,
                    $order->remark,$order->pay_time
                ];

                array_push($data,$value);
            }
        }

        return $data;
    }
}
